package com.iot.iotplus.controller;

import cn.hutool.crypto.SecureUtil;
import com.iot.iotplus.base.Result;
import com.iot.iotplus.entity.Device;
import com.iot.iotplus.service.DeviceService;
import com.iot.iotplus.utils.SnowflakeIdGenerator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;

@RestController
@RequestMapping("/device")
@CrossOrigin
public class DeviceController {
    @Autowired
    private DeviceService deviceService;
    @GetMapping("/{tid}/{pid}/{pageNum}/{pageSize}")
    public Result listDevice(@PathVariable("tid") String tenantId,
                             @PathVariable("pid") String productId,
                             @PathVariable("pageNum") Integer pageNum,
                             @PathVariable("pageSize") Integer pageSize){
        return deviceService.listDevice(tenantId, productId, pageNum, pageSize);
    }
    @GetMapping("/{tid}/{pageNum}/{pageSize}")
    public Result listDeviceByProduct(@PathVariable("tid") String tenantId,
                             @PathVariable("pageNum") Integer pageNum,
                             @PathVariable("pageSize") Integer pageSize){
        return deviceService.listDeviceByProduct(tenantId, pageNum, pageSize);
    }
    @GetMapping("/{id}")
    public Result selectOneDevice(@PathVariable("id") String id){
        return deviceService.selectOneDevice(id);
    }
    @DeleteMapping("/{id}")
    public Result deleteById(@PathVariable("id") String id){
        return deviceService.deleteById(id);
    }
    @PostMapping("/add")
    public Result addDevice(@RequestBody Device device){

        return deviceService.addDevice(device);
    }
    @GetMapping("/type/{id}")
    public Result<?> getDeviceType(@PathVariable("id") String typeId){
        return deviceService.getDeviceType(typeId);
    }
    @GetMapping("/upLink/{product}/{device}/{tenant}/{pageNum}/{pageSize}")
    public Result<?> getUpLinkData(@PathVariable("product") String product,
                                   @PathVariable("device") String device,
                                   @PathVariable("tenant") String tenant,
                                   @PathVariable("pageNum") Integer pageNum,
                                   @PathVariable("pageSize") Integer pageSize){
        return deviceService.getUpLinkData(product, device, tenant,pageNum,pageSize);
    }
    @GetMapping("/counts/{tenantId}")
    public Result<?> getProductCount(@PathVariable("tenantId" )String tenantId){
        return  deviceService.countProds(tenantId);
    }

    @GetMapping("/types")
    public Result listDeviceType(){
        return deviceService.listDes();
    }

    @GetMapping("/count")
    public Result count(String tenantId){
        return deviceService.countDevice(tenantId);
    }
}
